<?php
	class news_blacklistControl extends skymvc{
		function __construct(){
			parent::__construct();
		}
		
		public function onDefault(){
			$start=get('per_page','i');
			$limit=24;
			 
			$where="   siteid=".SITEID;
			$order="id DESC";
			$rscount=true;
			$url=APPADMIN."?m=news_blacklist";
			$keywords=get('keywords','h');
			if($keywords){
			 
				$url.="&keywords=".urlencode($keywords);
				$uids=M("user")->selectCols(array(
					"fields"=>"userid",
					"where"=>" nickname like '%".$keywords."%' " 
				));
				if($uids){
					$where.=" AND userid in("._implode($uids).")";
				}else{
					$where.=" AND 1=2 ";
				}
			}
			$option=array(
				"where"=>$where,
				"start"=>$start,
				"limit"=>$limit,
				"order"=>$order
			);
			$data=M("news_blacklist")->select($option,$rscount);
			
			if($data){
				$uids=array();
				foreach($data as $v){
					$uids[]=$v['userid'];
				}
				$us=M("user")->getUserByIds($uids); 
				
				
				foreach($data as $k=>$v){
					
					$v['nickname']=$us[$v['userid']]['nickname'];
					$v['user_head']=$us[$v['userid']]['user_head'];		
					
					$data[$k]=$v;
				}
			}
			$per_page=$start+$limit;
			$per_page=$per_page>=$rscount?0:$per_page;
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->goassign(array(
				"data"=>$data,
				"pagelist"=>$pagelist,
				"per_page"=>$per_page
			));
			$this->smarty->display("news_blacklist/index.html");
		}
		
		public function onForbid(){
			$userid=get('userid','i');
			$row=M("news_blacklist")->selectRow("userid=".$userid);
			!$row && M("news_blacklist")->insert(array(
				"userid"=>$userid,
				"siteid"=>SITEID,
				"dateline"=>time()
			));
		}
		public function onDelete(){
		 
			$id=get('id','i');
			$row=M("news_blacklist")->selectRow("id=".$id);
			if($row['siteid']!=SITEID){
				$this->goAll("暂无权限",1);
			}
			M("news_blacklist")->delete("id=".$id);
			$this->goAll("删除成功");
		}
		
		
	}
?>